package cn.edu.stu.syllabus.repository.library;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by daidaijie on 2017/3/27.
 */

public class LibrarySearchInfo implements Parcelable {

    String mKeyword;

    String mQueryWay;

    String mSortWay;

    String mOrderWay;

    public LibrarySearchInfo() {
    }

    public LibrarySearchInfo(String keyword, String queryWay, String sortWay, String orderWay) {
        mKeyword = keyword;
        mQueryWay = queryWay;
        mSortWay = sortWay;
        mOrderWay = orderWay;
    }

    public String getKeyword() {
        return mKeyword;
    }

    public void setKeyword(String keyword) {
        mKeyword = keyword;
    }

    public String getQueryWay() {
        return mQueryWay;
    }

    public void setQueryWay(String queryWay) {
        mQueryWay = queryWay;
    }

    public String getSortWay() {
        return mSortWay;
    }

    public void setSortWay(String sortWay) {
        mSortWay = sortWay;
    }

    public String getOrderWay() {
        return mOrderWay;
    }

    public void setOrderWay(String orderWay) {
        mOrderWay = orderWay;
    }

    public Map<String, String> getQueryMap() throws UnsupportedEncodingException {
        Map<String, String> queryMap = new HashMap<>();

        queryMap.put(mQueryWay, URLEncoder.encode(mKeyword, "gb2312"));
        queryMap.put("dt", "ALL");
        queryMap.put("cl", "ALL");
        queryMap.put("dept", "ALL");
        queryMap.put("sf", mSortWay);
        queryMap.put("ob", mOrderWay);
        queryMap.put("sm", "table");

        return queryMap;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.mKeyword);
        dest.writeString(this.mQueryWay);
        dest.writeString(this.mSortWay);
        dest.writeString(this.mOrderWay);
    }

    protected LibrarySearchInfo(Parcel in) {
        this.mKeyword = in.readString();
        this.mQueryWay = in.readString();
        this.mSortWay = in.readString();
        this.mOrderWay = in.readString();
    }

    public static final Parcelable.Creator<LibrarySearchInfo> CREATOR = new Parcelable.Creator<LibrarySearchInfo>() {
        @Override
        public LibrarySearchInfo createFromParcel(Parcel source) {
            return new LibrarySearchInfo(source);
        }

        @Override
        public LibrarySearchInfo[] newArray(int size) {
            return new LibrarySearchInfo[size];
        }
    };
}
